function formatTime2(date) {
    var year = date.getFullYear()
    var month = date.getMonth() + 1
    var day = date.getDate()
    var hour = date.getHours()
    var minute = date.getMinutes()
    var second = date.getSeconds()
    return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

function formatTime(time) {
    if (typeof time !== 'number' || time < 0) {
        return time
    }

    var hour = parseInt(time / 3600)
    time = time % 3600
    var minute = parseInt(time / 60)
    time = time % 60
    var second = time

    return ([hour, minute, second]).map(function(n) {
        n = n.toString()
        return n[1] ? n : '0' + n
    }).join(':')
}

function formatLocation(longitude, latitude) {
    if (typeof longitude === 'string' && typeof latitude === 'string') {
        longitude = parseFloat(longitude)
        latitude = parseFloat(latitude)
    }

    longitude = longitude.toFixed(2)
    latitude = latitude.toFixed(2)

    return {
        longitude: longitude.toString().split('.'),
        latitude: latitude.toString().split('.')
    }
}

function formatDate(date) {
    var year = date.getFullYear()
    var month = date.getMonth() + 1
    var day = date.getDate()

    if (date.getHours() >= 24) {
        day = day + 1;
    }

    return [year, month, day].map(formatNumber).join('-')
}

function formatNumber(n) {
    n = n.toString()
    return n[1] ? n : '0' + n
}
function formatDates(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate() + 1

  if (date.getHours() >= 24) {
    day = day + 1;
  }

  return [year, month, day].map(formatNumber).join('-')
}
function formatDatess(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate() + 19

  if (date.getHours() >= 24) {
    day = day + 1;
  }

  return [year, month, day].map(formatNumber).join('-')
}
function formatDatessz(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate() + 18

  if (date.getHours() >= 24) {
    day = day + 1;
  }

  return [year, month, day].map(formatNumber).join('-')
}
function stringToTime(string) {
  var f = string.split(' ', 2);
  var d = (f[0] ? f[0] : '').split('-', 3);
  var t = (f[1] ? f[1] : '').split(':', 3);
  return (new Date(
    parseInt(d[0], 10) || null,
    (parseInt(d[1], 10) || 1) - 1,
    parseInt(d[2], 10) || null,
    parseInt(t[0], 10) || null,
    parseInt(t[1], 10) || null,
    parseInt(t[2], 10) || null)).getTime();
}  
function dateAddDays(dataStr, dayCount) {
  var strdate = dataStr; //日期字符串
  var isdate = new Date(strdate.replace(/-/g, "/"));  //把日期字符串转换成日期格式
  isdate = new Date((isdate / 1000 + (86400 * dayCount)) * 1000);  //日期加1天
  var pdate = isdate.getFullYear() + "-" + (isdate.getMonth() + 1) + "-" + (isdate.getDate());   //把日期格式转换成字符串

  return pdate;
}
function dateAddDayz(dataStr, dayCount) {
  var strdate = dataStr; //日期字符串
  var isdate = new Date(strdate.replace(/-/g, "/"));  //把日期字符串转换成日期格式
  isdate = new Date((isdate / 1000 - (86400 * dayCount)) * 1000);  //日期加1天
  var pdate = isdate.getFullYear() + "-" + (isdate.getMonth() + 1) + "-" + (isdate.getDate());   //把日期格式转换成字符串

  return pdate;
}
//获取当前时间‘年-月-日 时：分’
function getNowTime() {
  var now = new Date();
  var year = now.getFullYear();
  var month = now.getMonth() + 1;
  var day = now.getDate();
  if (month < 10) {
    month = '0' + month;
  };
  if (day < 10) {
    day = '0' + day;
  };
   //如果需要时分秒，就放开
  var h = now.getHours();
  var m = now.getMinutes();
  var s = now.getSeconds();
  var formatDate = h+':'+m;
  return formatDate;
}
function haveSomeMinutesTime(n) {
  if (n == null) {
    n = 0;
  }
  // 时间
  var newDate = new Date()
  // var timeStamp = newDate.getTime(); //获取时间戳
  var date = newDate.setMinutes(newDate.getMinutes() + n);
  newDate = new Date(date);
  var year = newDate.getFullYear();
  var month = newDate.getMonth() + 1;
  var day = newDate.getDate();
  var h = newDate.getHours();
  var m = newDate.getMinutes();
  var s = newDate.getSeconds();
  if (month < 10) {
    month = '0' + month;
  };
  if (day < 10) {
    day = '0' + day;
  };
  if (h < 10) {
    h = '0' + h;
  };
  if (m < 10) {
    m = '0' + m;
  };
  if (s < 10) {
    s = '0' + s;
  };
  var time = h + ':' + m;
  return time;
}
module.exports = {
	haveSomeMinutesTime: haveSomeMinutesTime,
	getNowTime: getNowTime,
    formatTime: formatTime,
    formatDate: formatDate,
    formatDates: formatDates,
    stringToTime: stringToTime,
    formatDatess: formatDatess,
    dateAddDays: dateAddDays,
    dateAddDayz: dateAddDayz,
    formatDatessz: formatDatessz
}